<template>
    <el-dialog :model-value="dialogFormVisible" :destroy-on-close="true" :title="dialogTitle" width="450px" @close="emits('closeDialog')">
        <el-form ref="dialogFormRef" :model="dialogForm" prop="country_code" :rules="rules">
            <el-form-item label="国家编码" :label-width="formLabelWidth">
                <el-input v-model="dialogForm.country_code" />
            </el-form-item>
            <el-form-item label="支付通道ID" :label-width="formLabelWidth" prop="channel_id">
                <el-input v-model="dialogForm.channel_id" />
            </el-form-item>
            <el-form-item label="法币名称" :label-width="formLabelWidth" prop="currency">
                <el-input v-model="dialogForm.currency" />
            </el-form-item>
            <el-form-item label="手续费率" :label-width="formLabelWidth" prop="fee_rate">
                <el-input v-model="dialogForm.fee_rate" type="number" />
            </el-form-item>
            <el-form-item label="本币单笔固定费用" :label-width="formLabelWidth" prop="fixed_fee">
                <el-input v-model="dialogForm.fixed_fee" type="number" />
            </el-form-item>
            <el-form-item label="美元单笔固定费用" :label-width="formLabelWidth" prop="fixed_ued_fee">
                <el-input v-model="dialogForm.fixed_ued_fee" type="number" />
            </el-form-item>
            <el-form-item label="汇差费率" :label-width="formLabelWidth" prop="diff_rate">
                <el-input v-model="dialogForm.diff_rate" type="number" />
            </el-form-item>
            <el-form-item label="单笔最小限额" :label-width="formLabelWidth" prop="min_amount">
                <el-input v-model="dialogForm.min_amount" type="number" />
            </el-form-item>
            <el-form-item label="单笔最大限额" :label-width="formLabelWidth" prop="max_amount">
                <el-input v-model="dialogForm.max_amount" type="number" />
            </el-form-item>
            <el-form-item label="提现到账天数" :label-width="formLabelWidth" prop="withdraw_delay_days">
                <el-input v-model="dialogForm.withdraw_delay_days" type="number" />
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="emits('cancel')">取消</el-button>
                <el-button type="primary" @click="submit(dialogForm)" :loading="btnLoading">提交</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script setup>
import { ref } from "vue";

const dialogFormRef = ref(null);

defineProps({
    dialogFormVisible: {
        type: Boolean,
        default: false
    },
    dialogForm: {
        type: Object,
        default: {
            country_code: "",
            channel_id: "",
            currency: "",
            fee_rate: "",
            fixed_fee: "",
            fixed_ued_fee: "",
            diff_rate: "",
            min_amount: "",
            max_amount: "",
            withdraw_delay_days: ""
        }
    },
    btnLoading: {
        type: Boolean,
        default: false
    },
    dialogTitle: {
        type: String,
        default: ""
    }
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "140px";
// 校验
const rules = {
    country_code: [{ required: true, message: "请输入国家", trigger: "blur" }],
    channel_id: [{ required: true, message: "请输入支付通道ID", trigger: "blur" }],
    currency: [{ required: true, message: "请输入通道支持币种", trigger: "blur" }],
    fee_rate: [{ required: true, message: "请输入通道费率", trigger: "blur" }],
    // fixed_fee: [{ required: true, message: "请输入通道本币固定手续费", trigger: "blur" }],
    min_amount: [{ required: true, message: "请输入单笔最小金额", trigger: "blur" }],
    max_amount: [{ required: true, message: "请输入单笔最大金额", trigger: "blur" }],
};
// 提交
const submit = dialogForm => {
    dialogFormRef.value
        .validate()
        .then(async () => {
            try {
                const param = Object.assign({}, dialogForm);
                emits("submitForm", param);
            } catch (error) {
                console.log(error);
            }
        })
        .catch(error => {
            console.log(error);
        });
};
</script>
  